package com.javaenzk.wfx.manager.controller;

import com.javaenzk.wfx.manager.po.Wxb_Customer;
import com.javaenzk.wfx.manager.service.CustomerService;
import com.javaenzk.wfx.manager.service.ICustomerService;
import com.javaenzk.wfx.manager.util.ResultJson;

import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.UUID;


/**
 * 商户相关控制层
 */
@Controller
@RequestMapping("/merchant")
public class MerchantController {

    @Resource
    private CustomerService customerService;

    @RequestMapping("/list")
    @RequiresPermissions({"商户信息管理"})
    public String queryMerchantInfoList(Model model){

        try {
            final List<Wxb_Customer> wxbCustomers = customerService.queryALLcustomer();
            model.addAttribute("wxbCustomers",wxbCustomers);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "merchant-list";
    }

    @RequestMapping("/save")
    @ResponseBody
    public ResultJson saveMerchantInfo(Wxb_Customer wxb_customer){

        try {
            wxb_customer.setCreatetime(new Timestamp(new Date().getTime()));
            wxb_customer.setCustomer_Id(UUID.randomUUID().toString());
            customerService.addCustomer(wxb_customer);
           return ResultJson.createSuccessResult(null);
        } catch (Exception e) {
            e.printStackTrace();
           return ResultJson.createFailResult("1","error");
        }


    }
}
